import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class JailPanel extends JPanel
{
	private final int WIDTH = 210;
	private final int HEIGHT = 300;
	
	private JLabel rollLabel, fineLabel, chanceLabel, chestLabel;
	private JButton RollDiceButton, PayFineButton, ChanceButton, ChestButton;
	private int returnValue; // 0 - RollDice, 1 - PayFine

	public JailPanel(Player p)
	{
		setPreferredSize(new Dimension(WIDTH, HEIGHT));
		setBackground(new Color(200,222,186));
		returnValue = -1; // used to force user to choose yes or no
		
		rollLabel = new JLabel("Roll Dice for doubles? ");
		fineLabel = new JLabel("Pay $50 fine to get out? ");
		chanceLabel = new JLabel("Use jail free Chance card? ");
		chestLabel = new JLabel("Use jail free Comm. Chest card? ");
		
		RollDiceButton = new JButton("Roll Dice");
		PayFineButton = new JButton("Pay $50");
		ChanceButton = new JButton("Use Chance");
		ChestButton = new JButton("Use Chest");
		
		RollDiceButton.addActionListener(new ButtonListener());
		PayFineButton.addActionListener(new ButtonListener());
		ChanceButton.addActionListener(new ButtonListener());
		ChestButton.addActionListener(new ButtonListener());
		
		add(rollLabel);
		add(RollDiceButton);
		add(fineLabel);
		add(PayFineButton);
		
		if(p.getJailFreeChance() == true)
		{
			add(chanceLabel);
			add(ChanceButton);
		}
		if(p.getJailFreeCommChest() == true)
		{
			add(chestLabel);
			add(ChestButton);
		}
		
		
	}
	
	private class ButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			Object source = event.getSource();
			if(source == RollDiceButton)
				returnValue = 0;
			else if(source == PayFineButton)
				returnValue = 1;
			else if(source == ChanceButton)
				returnValue = 2;
			else if(source == ChestButton)
				returnValue = 3;
		}
	}
	
	
	public int getReturnValue()
	{
		return returnValue;
	}
	
	public void resetReturnValue()
	{
		returnValue = -1;
	}

}
